
var __checked = false;

function checkPost() {
    if (!__checked) {
        __checked = true;
        return true;
    }
    return false;
}

/**
 * Returns an element by ID
 */
function getElement(id) {
    if (document.layers) {
        return document.layers[id];
    }
    else if (document.all) {
        return document.all[id];
    }
    else if (document.getElementById) {
        return document.getElementById(id);
    }
}

/**
 * Hides a DIV given its ID.
 */
function hideDiv(divId) {
    if (document.layers) {
        document.layers[divId].visibility = 'hide';
    }
    else if (document.all) {
        document.all[divId].style.visibility = 'hidden';
    }
    else if (document.getElementById) {
        document.getElementById(divId).style.visibility = 'hidden';
    }
}
function hideDiv2(divId) {
    if (document.layers) {
        document.layers[divId].display = 'none';
    }
    else if (document.all) {
        document.all[divId].style.display = 'none';
    }
    else if (document.getElementById) {
        document.getElementById(divId).style.display = 'none';
    }
}
function hideDiv2ByElement(el) {
    if (document.layers) {
        el.display = 'none';
    }
    else if (document.all) {
        el.style.display = 'none';
    }
    else if (document.getElementById) {
        el.style.display = 'none';
    }
}

function hideAllElementsByClass(classname) {
    var elements = document.getElementsByClassName(classname);
    for (var i = 0; i < elements.length; i++) {
        hideDiv2ByElement(elements[i]);
    }
}

/**
 * Shows a DIV given its ID.
 */
function showDiv(divId) {
    showDivByDoc(divId, document);
}

/**
 * Shows a DIV given its ID and the document it's located in.
 */
function showDiv2ByElement(el) {
    if (document.layers) {
        el.display = 'block';
    }
    else if (document.all) {
        el.display = 'block';
    }
    else if (document.getElementById) {
        el.style.display = 'block';
    }
}
function showDiv2(divId) {
    if (document.layers) {
        document.layers[divId].display = 'block';
    }
    else if (document.all) {
        document.all[divId].style.display = 'block';
    }
    else if (document.getElementById) {
        document.getElementById(divId).style.display = 'block';
    }
}
function setDisplay(divId, display) {
    if (document.layers) {
        document.layers[divId].display = display;
    }
    else if (document.all) {
        document.all[divId].style.display = display;
    }
    else if (document.getElementById) {
        document.getElementById(divId).style.display = display;
    }
}

/**
 * Removes a DOM node given its ID.
 */
function removeNodeById(nodeId) {
    node = document.getElementById(nodeId);
    if (node) {
        if (node.parentNode) {
            node.parentNode.removeChild(node);
        }
    }
}

/**
 * Makes a copy of the first child node of the given parent. The child is specified
 * by the given classname.
 */
function cloneFirstChild(parent, childTag) {
    var children = parent.getElementsByTagName(childTag);
    if (children[0]) {
        return children[0].cloneNode(true);
    }
    else {
        return null;
    }
}

/**
 * Work around function to return the value of teh requested node attribute.
 */
function getAttribute(n, name) {
    if (!node) {
        return;
    }
    if (node.getAttributeNode(name)) {
        for (var i = 0; i < node.attributes.length; i++) {
            var attrName = node.attributes[i].name.toUpperCase();
            if (attrName == name.toUpperCase()) {
                return node.attributes[i].value;
            }
        }
    }
    else {
        return node.getAttribute(name);
    }
}

/**
 * Work around function because of browser incompatibility w/ setting node attribute values.
 */
function setAttribute(node, name, value) {
    if (!node) {
        return;
    }
    // Get the value of the current node..
    if (node.getAttributeNode(name)) {
        for (var i = 0; i < node.attributes.length; i++) {
            var attrName = node.attributes[i].name.toUpperCase();
            if (attrName == name.toUpperCase()) {
                node.attributes[i].value = value;
            }
        }
    }
    else {
        node.setAttribute(name, value);
    }
}
function setAttributeByID(nodeID, name, value) {
    var node = getElement(nodeID);
    if (!node) {
        return;
    }
    // Get the value of the current node..
    if (node.getAttributeNode(name)) {
        for (var i = 0; i < node.attributes.length; i++) {
            var attrName = node.attributes[i].name.toUpperCase();
            if (attrName == name.toUpperCase()) {
                node.attributes[i].value = value;
            }
        }
    }
    else {
        node.setAttribute(name, value);
    }
}

/**
 * Adds a hidden variable to the given form. If the variable already exists
 * its value is updated. If the given value is null then the hiddent variable will
 * be removed. Blank values can be set. Additionally, name can be a valid regex
 * and any matching parameters will be set.
 */
function setHidden(form, name, value) {
    var nameIsPattern = setHidden.arguments[3] ? true : false;
    var f = (form.name) ? form : $(form);
    if (!nameIsPattern && f.elements[name] && value == null) {
        var element = f.elements[name];
        element.parentNode.removeChild(element);
    }
    else {
        var names = new Array();
        if (!nameIsPattern) {
            names.push(name);
        }
        if (nameIsPattern) {
            // loop through all elements, match the name:
            var re = new RegExp(name);
            for (var i = 0; i < f.elements.length; i++) {
                if (f.elements[i].name && f.elements[i].name.search(re) > -1) {
                    names.push(f.elements[i].name);
                }
            }
        }
        for (var i = 0; i < names.length; i++) {
            var n = names[i];
            if (value == null) {
                setHidden(form, n, null, false);
            }
            else {
                if (f.elements[n]) {
                    f.elements[n].value = value;
                }
                else {
                    var hidden = document.createElement('INPUT');
                    hidden.type = "hidden";
                    hidden.name = n;
                    hidden.value = value;
                    f.appendChild(hidden);
                }
            }
        }
    }
}